package com.example.filesystem.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 映射上传目录
        registry.addResourceHandler("/filetrans/uploads/**")
                .addResourceLocations("file:uploads/");  // 根据实际路径调整

        // 映射静态资源
        registry.addResourceHandler("/filetrans/css/**")
                .addResourceLocations("classpath:/static/css/");
        registry.addResourceHandler("/filetrans/js/**")
                .addResourceLocations("classpath:/static/js/");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // 简单的URL到视图的映射，不需要控制器逻辑
        registry.addViewController("/filetrans").setViewName("index");
        registry.addViewController("/filetrans/login").setViewName("login");
        registry.addViewController("/filetrans/register").setViewName("register");
    }
}